<template name='user_level'>

<view style="display: flex;    height: 100%;">
	<!-- 商品信息-右边 -->
	<view class="box-infos font12  " >

			<!-- 记录 -->
			<view class="content-box" >
				<view class="boxsss100" >
					<view class="top-but" style="height: auto;">
						<view class="top-but-box background-fff">
							<text selectable="true"   class="tipss ">价格分组;常用于区分客户群体后根据群体进行设置相应的价格\n亦可用作会员体系，用户自行购买后可以享受区别于正常批发价的其他价格；\n若要设置某个分组为销售分组则必须设置某分组的价格；\n用户可使用微信在线支付或卡密兑换方式进行兑换分组;\n用户使用卡密可兑换下方已设置的销售分组(任意一个已设置的)</text>
							<!-- 搜索 -->
						
							<button @click="$common.noMultipleClicks('loadLevel',loadLevel,true)" 
							class="leftBut color1"
							>
								<img src="../../static/img/search.png" class="ico" ></img>
								刷新
							</button>
							
							
							<button @click="$common.noMultipleClicks('openAddCard',openAddCard,'card')" 
							class="leftBut color1" 
							>
								管理余额充值卡密[{{DayCount.card}}]
							</button>
						</view>
					</view>
							
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers ">
									序
								</th>
								<th>
									名称(点击可进行修改名称)
								</th>
								<th>
									用户数
								</th>
								<th>
									<view class="flex">
										<text class="justify">用户购买此分组30天的金额；为0则不能自行购买；</text>
										<button @click="$common.noMultipleClicks('openAddCard',openAddCard,'month')"
										class="leftBut color1" 
										>
											管理[{{DayCount.month}}]
										</button>
									</view>
								</th>
								<th>
									<view class="flex">
										<text class="justify">用户购买此分组365天的金额；为0则不能自行购买；</text>
										<button @click="$common.noMultipleClicks('openAddCard',openAddCard,'year')"
										class="leftBut color1" 
										>
											管理[{{DayCount.year}}]
										</button>
									</view>
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr v-for="(item,index) in resData.list"
							:key="index"
							@click="TabcheckedIndex = index"
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							class="font14"
							v-if="item.level_id.length>0 && parseFloat(item.id)>0"
							>
								<td selectable="true"   class="centers ">
									{{index+1}}
								</td>
							
								<td selectable="true"   
								class="  cursor" 
								:title="$global.title.m28+'\nid：'+item.level_id"
								>
									<input
									:disabled="item.level_id==0"
									:auto-height="true"
									v-model="item.text" 
									@confirm="Level_update(item.text,item.level_id)"
									class=" white-space goodsNameColor font14"
									/>
								</td>
								<td selectable="true"  class="cursor " 
								@click="openUserList(item)"
								>
									<text class="alter ">{{item.user_count}}</text>
								</td>
								<td selectable="true" v-if="item.level_id!=0" >
									<view class="flex gap10">
										<view class="flex gap10" @click="settingLevelMoney(item,index,1)" :style="item.month_money<=0 ?'color: #ff2626;':'color: #106501'">
											<text selectable="true">
												金额：{{item.month_money}}元
											</text>
											<view class="alter">
												设置价格
											</view>
										</view>
									</view>
								</td>
								<td selectable="true" v-if="item.level_id!=0" >
									<view class="flex gap10">
										<view class="flex gap10" @click="settingLevelMoney(item,index,2)" :style="item.year_money<=0 ?'color: #ff2626;':'color: #106501'">
											<text selectable="true">
												金额：{{item.year_money}}元
											</text>
											<view class="alter">
												设置价格
											</view>
										</view>
									</view>
								</td>
							</tr>
						</tbody>
					</table>

					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
			</view>
			
		

	</view>
	<!-- 用户页面 -->
	<uni-popup ref="pageUser" type="center" :title="pageSend.name">
		<person_admin  class="h100" :OnLevelId="pageSend.id" status="firm_user_list"></person_admin>
	</uni-popup>
	<!-- end -->
	<!-- 卡密 -->
	<uni-popup v-if="TabcheckedIndex>=0" ref="level_card" type="center" title="卡密管理`" >
		<level_card  :typeName="typeName"></level_card>
	</uni-popup>
	<!-- end -->
</view>
</template>

<script>
	import level_card from "@/components/user/level_card.vue"
	import empty from "@/components/admin-components/empty.vue"
	export default{
		name:'user_level',
		components: {
			empty,level_card
		},
		beforeCreate(){
			this.$options.components.person_admin = require('@/components/user/list.vue').default 
		},
		data(){
			return{
				DayCount:{
					month:0,
					year:0,
					card:0
				},
				typeName:'month',
				addName:'',
				TabcheckedIndex:-1,
				pageSend:{//欲要传递到权限页面搜寻的内容
					id:'',//可能是user_id,goods_id
					name:''
				},
				resData:{
					list:[]
				},
			}
		},
		 // 此处定义传入的数据

		created() {
			
			this.loadLevel();
		},

		methods:{
			openAddCard(value){
				this.typeName = value
				this.$refs.level_card.open()
			},
			openUserList(item){
				if(item.user_count<=0){
					this.$common.showModal("错误","此项无更多数据！")
					return
				}
				this.pageSend.name = item.text+"下的用户"
				this.pageSend.id = item.level_id
				this.$refs.pageUser.open()
			},
			loadLevel(){
				var that = this
				that.$routeData.loadLevel((res)=>{
					that.resData.list = that.$routeData.getLevel()
					console.log(res)
					that.DayCount.month = res.card.month
					that.DayCount.year = res.card.year
					that.DayCount.card = res.card.card
				})
			},
			Level_update(name,id){
				var that = this
				this.$routeData.Level_update(name,id,()=>{
					that.resData.list = that.$routeData.getLevel()
				})
			},
			settingLevelMoney(item,index,mode){
				var that = this
				uni.showModal({
					title:'输入用户自助购买此分组的金额(单位/元)',
					mask:true,
					editable:true,
					placeholderText:'请输入大于等于0的金额',
					success:(res)=>{
						if(res.confirm ){
							if(res.content.length==0){
								that.$common.showModal('提示',"未输入内容")
								return
							}
							var card = res.content.trim();
							var value = card.split("\n");
							value = parseFloat(value)
							if(value<0){
								that.$common.showModal('提示',"输入的金额不能小于0")
								return
							}
							that.$common.get_request(
								{
									type:'LevelUpdateMoney',
									update_id:item.id,
									money:value,
									mode:mode
								},
								(e)=>{
									that.loadLevel()
								}
							);
						}
					}
				})
			},

		}
	}
</script>

<style>
</style>
